//
//  policyConsultView.m
//  Project two framework
//
//  Created by rimi on 16/7/23.
//  Copyright © 2016年 张峥. All rights reserved.
//

#import "policyConsultView.h"
#import "policyConsultCell.h"
#import "ZPZNetRequest.h"
#import "LStringUtils.h"
#import "AFNetworking.h"
#import "PolicyConsultContentView.h"
#import "ZPZNetRequest+MealsList.h"


@interface policyConsultView ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *array;
/**头部阴影*/
@property(nonatomic,strong)UIImageView *headImage;
/**尾部阴影*/
@property(nonatomic,strong)UIImageView *foodImage;

@property(nonatomic,strong)UILabel *label1;
@property(nonatomic,strong)UILabel *label2;
@property(nonatomic,strong)PolicyConsultContentView *policyConsultContentView;
@end

@implementation policyConsultView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self ) {
        self.backgroundColor = [UIColor clearColor];
        self.frame = CGRectMake(45, 120, 825, 455);
//        _array = [[NSMutableArray alloc]init];
        [self tableView];
        [self headImage];
        [self foodImage];
        [self label2];
        [self label1];
        _policyConsultContentView = [[PolicyConsultContentView alloc]init];
//        PolicyConsultContentView *polict = [PolicyConsultContentView new];
//        _policyConsultContentView.frame = CGRectMake(0, 0, 800, 400);
        _policyConsultContentView.hidden = YES;
        [self addSubview:_policyConsultContentView];
        

    }

    return self;
}


#pragma mark --cell点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
//    [self addSubview:[PolicyConsultContentView showAnimation]];
    
    

}



#pragma mark --数据源
-(NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (_array.count < 8) {
        return 8;
    } else {
        return _array.count;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIndex = @"cellllllllll";
    policyConsultCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndex];
    if (cell == nil) {
        cell = [[policyConsultCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndex];
        
    }


    if (indexPath.row < _array.count) {
        cell.titleLabel.text = _array[indexPath.row][@"title"];
        cell.serialNumberLabel.text = [NSString stringWithFormat:@"%ld",(indexPath.row+1)];
    }
 

    return cell;
}



-(void)initializeDataSource{
    [ZPZNetRequest getAdviceListPageSize:@"10" PageNum:@"1" byTitle:@"" byKeywords:@"" comletion:^(id object, BOOL success) {
        if (success) {
            _array= [NSMutableArray arrayWithArray:object[@"content"]];
            
            [_tableView reloadData];
        }

        
    }];
    
}




-(UILabel *)label1
{
    if (_label1 == nil) {
        _label1 = [[UILabel alloc]initWithFrame:CGRectMake(100, 0, 60, 40)];
        _label1.text = @"序号";
        _label1.font = [UIFont boldSystemFontOfSize:16];
        _label1.textColor = [UIColor whiteColor];
        [self addSubview:_label1];
    }
    return _label1;
}

-(UILabel *)label2
{
    if (_label2 == nil) {
        _label2 = [[UILabel alloc]initWithFrame:CGRectMake(470, 0, 60, 40)];
        _label2.text = @"标题";
        _label2.font = [UIFont boldSystemFontOfSize:16];
        _label2.textColor = [UIColor whiteColor];
        [self addSubview:_label2];
    }
    return _label2;
}

-(UIImageView *)headImage{
    if (_headImage == nil) {
        _headImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 40, 845, 10)];
        _headImage.image = [UIImage imageNamed:@"up_19.png"];
        [self addSubview:_headImage];
    }
    return _headImage;
}

-(UIImageView *)foodImage{
    if (_foodImage == nil) {
        _foodImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 435, 845, 10)];
        _foodImage.image = [UIImage imageNamed: @"down_27.png"];
        [self addSubview:_foodImage];
    }
    return _foodImage;
}


-(UITableView *)tableView{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(10, 40, 825, 400) style:UITableViewStylePlain];
        _tableView.rowHeight = 50;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self initializeDataSource];
        [self addSubview:_tableView];
    }

    return _tableView;
}
@end
